{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "6abe0421-2888-44f6-b1f7-9c48bcf7c311",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#创建列表\n",
    "list=[1,2,3,'four','five']\n",
    "#查看指定位置处的元素\n",
    "list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "9276c143-56ef-49ba-8f29-b546e35cb0e1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 'four', 'five', 2024]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#像列表中添加一个新元素\n",
    "list.append(2024)\n",
    "list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "7328b070-9b0d-4e38-898d-735fd27a1d3d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 'four', 'five', 2024]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 删除位于位置2上的元素\n",
    "del list[2]\n",
    "list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "617970ec-144d-41b5-a09f-9007907976b1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 'hahaha', 'five', 2024]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#修改位于位置2上的列表元素\n",
    "list[2]='hahaha'\n",
    "list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "524b70dc-b49e-4313-8b84-2db2ed2806d2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#返回列表长度\n",
    "len(list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "12277805-ec19-49e4-a7a2-959fa3c5a69c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    }
   ],
   "source": [
    "a=1\n",
    "b=2\n",
    "c=3\n",
    "#具体的例子，找到a,b,c中最大的数，其中and 是逻辑运算符‘且’的意思\n",
    "if a>b and a>c:\n",
    "    print(a)\n",
    "elif b>a and b>c:\n",
    "    print(b)\n",
    "else:\n",
    "    print(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "9663d14d-578b-48c6-b48e-13a67521e36e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "10\n",
      "10\n",
      "10\n",
      "10\n",
      "10\n",
      "10\n",
      "10\n",
      "10\n"
     ]
    }
   ],
   "source": [
    "a=10\n",
    "b=1\n",
    "#循环语句的使用\n",
    "while a>b:\n",
    "    print(a)\n",
    "    b=b+1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "9bb940a5-4f0f-4441-8b2d-52099376c443",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "#for循环的使用\n",
    "for i in range(0,10):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "b7168dbd-669d-4cde-96cb-1a0097412fbc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 'hahaha', 'five', 2024, '小猫', '小狗', '小耗子']"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#列表相加，返回一个新的列表，里面按顺序有两个列表的所有数据\n",
    "list2=['小猫','小狗','小耗子']\n",
    "list3=list+list2\n",
    "list3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "5adf4b11-6175-4ed6-bf54-64c8b8136978",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "this is a long long long long long long long long long long long long string\n"
     ]
    }
   ],
   "source": [
    "#换行,代码太长，需要分割多行，可以使用\"\\\"连接\n",
    "longstring='this is a long long long long long long long long long long long long \\\n",
    "string'\n",
    "print(longstring)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "142b7040-b7dd-4f95-b51b-57cb27a3166e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
